Skip to content

Fix project config ordering for partial loaded elementSources entries#18719

Merged
brandonkelly merged 1 commit intocraftcms:5.xfrom
SLASH2NL:5.x
Apr 22, 2026
Merged

Fix project config ordering for partial loaded elementSources entries#18719
brandonkelly merged 1 commit intocraftcms:5.xfrom
SLASH2NL:5.x

Conversation

@wvell
Copy link
Copy Markdown
Contributor

@wvell wvell commented Apr 15, 2026

Description

When project config is applied to a clean install, pending changes are currently
sorted only by path depth. That can cause sections changes to be processed
before related elementSources entries are fully constructed.

In our case, handleChangedSection() ends up reading element sources while an
elementSources entry only contains nested values like defaultSort and
tableAttributes, but is still missing scalar keys such as type. That leads
to:

Undefined array key "type"

in ElementSources::defineSources().

Before After
elementSources...defaultSort elementSources...defaultSort
elementSources...tableAttributes elementSources...tableAttributes
sections...siteSettings elementSources...0
elementSources...0 sections...siteSettings
sections...entryTypes sections...entryTypes

Before this change, sections...siteSettings could run before the parent
elementSources...0 entry had been fully applied. After this change, all
elementSources paths are processed first, so section change handlers never
observe partially-built element source configs.

This change sorts pending changes by top-level config key first, and then by
depth within each group.

A minimal regression test has been added to reproduce that failure mode.

Related issues

#18720

Applying project config to a clean install only sorted keys by depth.
This allowed `sections` changes to run before related
`elementSources` entries were fully built. Resulting in the error:

    In ElementSources.php line 147:

      Undefined array key "type"

Sort pending changes by top-level key first, then by depth within each
group. This makes sure only complete elements are applied.
@brandonkelly
Copy link
Copy Markdown
Member

Can you send your project config files and Composer files into support@craftcms.com so we can look into this?

If I’m reading the changes right, the PR’d fix seems to be relying on the fact that elementSources comes alphabetically before sections, which doesn’t seem like a very solid solution.

@brandonkelly brandonkelly merged commit 79dd051 into craftcms:5.x Apr 22, 2026
@brandonkelly
Copy link
Copy Markdown
Member

Nevermind, I was able to reproduce the issue with the test you added, and wrapped my head around the issue.

Modified your fix a bit so that paths are sorted by their similarity across all path segments, not just the first one (cf50e0b), and merged it in for the next release.

Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants